
Component({
  data: {
    active: 1,
    list: [{
        "iconPath": "/assets/image/tabBar/a.png",
        "selectedIconPath": "/assets/image/tabBar/a_a.png",
        "url": "/pages/index/index",
        "text": "首页",
      },
      {
        "iconPath": "/assets/image/tabBar/d.png",
        "selectedIconPath": "/assets/image/tabBar/d_a.png",
        "url": "/pages/my/my",
        "text": "我的",
      }
    ]
  },
  attached() {
    // this.init()
    // console.log('attached')
  },
  ready() {
    this.init()
  },
  methods: {
    onChange(event) {
      let url = ''
      const list = this.data.list
      url = list[event.detail].url
      wx.switchTab({
        url,
      });
    },
    init() {
      const page = getCurrentPages().pop();
      const list = this.data.list;
      const active = list.findIndex(item => item.url === `/${page.route}`)
      this.setData({
        active,
        list: list
      });
    }
  }
});